package com.example.fangyh09.viewpager;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends FragmentActivity  implements ViewPager.OnPageChangeListener{
    private List<View> viewList;
    ViewPager viewPager;
    PagerTabStrip tab;
    List<String> titlelist;
    List<Fragment> fraglist;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewList = new ArrayList<View>();
        titlelist = new ArrayList<String>();
        tab = (PagerTabStrip)findViewById(R.id.tab);
        tab.setBackgroundColor(Color.YELLOW);
        tab.setTextColor(Color.RED);
        tab.setDrawFullUnderline(false);
        tab.setTabIndicatorColor(Color.GREEN);

        View view1 = View.inflate(this,R.layout.view1,null);
        View view2 = View.inflate(this,R.layout.view2,null);
        View view3 = View.inflate(this,R.layout.view3,null);
        View view4 = View.inflate(this,R.layout.view4,null);

        viewList.add(view1);
        viewList.add(view2);
        viewList.add(view3);
        viewList.add(view4);

        titlelist.add("1");
        titlelist.add("2");
        titlelist.add("3");
        titlelist.add("4");

        fraglist = new ArrayList<Fragment>();
        fraglist.add(new Fragment1());
        fraglist.add(new Fragment2());
        fraglist.add(new Fragment3());
        fraglist.add(new Fragment4());

      //  MyPagerAdapter adapter = new MyPagerAdapter(viewList,titlelist);

        viewPager = (ViewPager) findViewById(R.id.pager);
        //viewPager.setAdapter(adapter);

        MyFragmentPageAdapter adapter1 = new MyFragmentPageAdapter(getSupportFragmentManager(),fraglist,titlelist);
        MyFragmentPageAdapter2 adapter = new MyFragmentPageAdapter2(getSupportFragmentManager(),fraglist,titlelist);

        viewPager.setAdapter(adapter);
        viewPager.setOnPageChangeListener(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        Toast.makeText(this,"pos is" + position,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}




























